package app

import (
	"chatgpt/helper/code"
	"chatgpt/logq"
	"chatgpt/plugin/rpcx"
	"chatgpt/services/datasrv/sqlhelper"
	"context"
)

func (self *AppApi) ScopeSelect(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("AppApi")
	err := client.Call(ctx, "ScopeSelect", req, res)
	if err != nil {
		logq.Error("DataSrv.Scope.Select err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}

func (self *AppApi) ScopeSave(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("AppApi")
	err := client.Call(ctx, "ScopeSave", req, res)
	if err != nil {
		logq.Error("DataSrv.Scope.Save err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}

func (self *AppApi) ScopeTotal(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("AppApi")
	err := client.Call(ctx, "ScopeTotal", req, res)
	if err != nil {
		logq.Error("DataSrv.Scope.Total err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}

func (self *AppApi) ScopeFirst(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("AppApi")
	err := client.Call(ctx, "ScopeFirst", req, res)
	if err != nil {
		logq.Error("DataSrv.Scope.Total err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}

func (self *AppApi) ScopeDelete(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("AppApi")
	err := client.Call(ctx, "ScopeDelete", req, res)
	if err != nil {
		logq.Error("DataSrv.Scope.Delete err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}
